package cn.hesion.dataStructures.Stack;

import java.util.Scanner;

public class LinkedListStackDemo {
    public static void main(String[] args) {
        LinkedListStack stack = new LinkedListStack();
        String key ="";
        boolean loop=true;
        Scanner scanner = new Scanner(System.in);
        while (loop){
            System.out.println("show:表示显示栈");
            System.out.println("exit:表示退出程序");
            System.out.println("push:表示添加数据到栈中（）入栈");
            System.out.println("pop:表示从栈取出数据（出栈）");
            System.out.println("showNum:表示栈中的元素个数");
            key=scanner.next();
            switch (key){
                case "show":
                    stack.list();
                    break;
                case "push":
                    System.out.println("进入入栈操作：");
                    System.out.println("请输入一个数字：");
                    int value=scanner.nextInt();
                    stack.push(value);
                    break;
                case "pop":
                    System.out.println("进入出栈操作");
                    try {
                        System.out.println("出栈元素为:"+stack.pop());
                    }catch (Exception e){
                        e.printStackTrace();
                    }
                    break;
                case "exit":
                    scanner.close();
                    loop=false;
                    break;
                case "showNum":
                    System.out.println("栈中的元素个数："+stack.getNumInStack());
                    break;
                default:
                    break;
            }

        }
        System.out.println("程序退出，再见！");
    }
}

